package com.dataaccess.dataaccess.support.utils;

import cn.hutool.core.codec.Base64Decoder;
import cn.hutool.core.util.HexUtil;

public class HexToASCIIUtils {
    /**
     * 16进制 转 ASCII码
     * @param “3030313030312d30303300000000000000000000”
     * @return 001001-003
     */
    public static String convertHexToString(String hex) {

        StringBuilder sb = new StringBuilder();
        StringBuilder temp = new StringBuilder();

        //49204c6f7665204a617661 split into two characters 49, 20, 4c...
        for (int i = 0; i < hex.length() - 1; i += 2) {

            //grab the hex in pairs
            String output = hex.substring(i, (i + 2));
            if (!output.equals("00")) {
                //convert hex to decimal
                int decimal = Integer.parseInt(output, 16);
                //convert the decimal to character
                sb.append((char) decimal);

                temp.append(decimal);
            }
        }

        return sb.toString();

    }

    public static void main(String[] args) {

    }
}
